<?php

namespace Fuel\Migrations;

class Create_moviegenres
{
	public function up()
	{
		\DBUtil::create_table('movie_genres', array(
			'id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true),
			'movie_id' => array('constraint' => 11, 'type' => 'int'),
			'genre_id' => array('constraint' => 11, 'type' => 'int')
		), array('id'));
                
                $movie_genres = array(
                    1 => array(1),
                    2 => array(1,6,4),
                    3 => array(6,7,8),
                    4 => array(8),
                    5 => array(6),
                    6 => array(8)
                );
                
                foreach($movie_genres as $movie_id => $movie_genre_ids) {
                    foreach($movie_genre_ids as $genre_id) {
                        $moviegenre = \Model_Orm_Moviegenre::forge();
                        $moviegenre->movie_id = $movie_id;
                        $moviegenre->genre_id = $genre_id;
                        $moviegenre->save();
                    }
                }
	}

	public function down()
	{
		\DBUtil::drop_table('movie_genres');
	}
}